package com.example.neusoft215gdh.androidpro_21.Activity;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;

import com.example.neusoft215gdh.androidpro_21.Adapter.LoveAdapter;
import com.example.neusoft215gdh.androidpro_21.Fragement.BaseActivity;
import com.example.neusoft215gdh.androidpro_21.JavaBean.LoveList;
import com.example.neusoft215gdh.androidpro_21.R;
import com.example.neusoft215gdh.androidpro_21.Service.ClubService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Rainbow on 2017/11/12.
 */

public class LoveActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private LoveAdapter adapter;
    private ImageButton back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_love);

        recyclerView = (RecyclerView)findViewById(R.id.recyclerView_love);
        back= (ImageButton) findViewById(R.id.love_back);
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175/workout/api.php/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ClubService clubSeverice =retrofit.create(ClubService.class);
        Call<List<LoveList>> listCall = clubSeverice.lovelist("46",46);

        listCall.enqueue(new Callback<List<LoveList>>() {
            @Override
            public void onResponse(Call<List<LoveList>> call, Response<List<LoveList>> response) {

                List<LoveList>  loveList =response.body();

                if (LoveActivity.this != null) {
                    adapter = new LoveAdapter(LoveActivity.this, loveList);
                    LinearLayoutManager layoutManager = new LinearLayoutManager(LoveActivity.this);
                    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                    recyclerView.setLayoutManager(layoutManager);
                    recyclerView.setAdapter(adapter);
                    recyclerView.setItemAnimator(new DefaultItemAnimator());
                }
            }

            @Override
            public void onFailure(Call<List<LoveList>> call, Throwable t) {

            }
        });

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }
}
